import defaultSettings from '@/settings'

const { showSettings, fixedHeader, sidebarLogo } = defaultSettings

const state = {
  /**
   * 是否显示设置面板
   * @type {boolean}
   */
  showSettings: showSettings,
  /**
   * 是否固定头部
   * @type {boolean}
   */
  fixedHeader: fixedHeader,
  /**
   * 是否在侧边栏显示Logo
   * @type {boolean}
   */
  sidebarLogo: sidebarLogo
}

const mutations = {
  /**
   * 修改设置项的值
   * @param {Object} state Vuex store 的状态对象
   * @param {Object} param0 参数对象
   * @param {string} param0.key 设置项的键名
   * @param {*} param0.value 设置项的新值
   */
  CHANGE_SETTING: (state, { key, value }) => {
    // eslint-disable-next-line no-prototype-builtins
    if (state.hasOwnProperty(key)) {
      state[key] = value
    }
  }
}

const actions = {
  /**
   * 修改设置项的值
   * @param {Object} context Vuex store 上下文对象
   * @param {Object} data 参数对象
   * @param {string} data.key 设置项的键名
   * @param {*} data.value 设置项的新值
   */
  changeSetting({ commit }, data) {
    commit('CHANGE_SETTING', data)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
